package com.debao.web.controller.debao;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.debao.system.domain.CourseCard;
import com.debao.system.service.ICourseCardService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.debao.common.annotation.Log;
import com.debao.common.core.controller.BaseController;
import com.debao.common.core.domain.AjaxResult;
import com.debao.common.enums.BusinessType;
import com.debao.system.domain.Appoint;
import com.debao.system.service.IAppointService;
import com.debao.common.utils.poi.ExcelUtil;
import com.debao.common.core.page.TableDataInfo;

/**
 * 上课预约Controller
 *
 * @author DeBao
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/debao/appoint")
public class AppointController extends BaseController
{
    @Autowired
    private IAppointService appointService;

    @Resource
    private ICourseCardService courseCardService;

    /**
     * 查询上课预约列表
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:list')")
    @GetMapping("/list")
    public TableDataInfo list(Appoint appoint)
    {
        startPage();
        List<Appoint> list = appointService.selectAppointList(appoint);
        return getDataTable(list);
    }

    /**
     * 导出上课预约列表
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:export')")
    @Log(title = "上课预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Appoint appoint)
    {
        List<Appoint> list = appointService.selectAppointList(appoint);
        ExcelUtil<Appoint> util = new ExcelUtil<Appoint>(Appoint.class);
        util.exportExcel(response, list, "上课预约数据");
    }

    /**
     * 获取上课预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appointService.selectAppointById(id));
    }

    /**
     * 新增上课预约
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:add')")
    @Log(title = "上课预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appoint appoint)
    {
        return toAjax(appointService.insertAppoint(appoint));
    }

    /**
     * 修改上课预约
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:edit')")
    @Log(title = "上课预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appoint appoint)
    {
        return toAjax(appointService.updateAppoint(appoint));
    }

    /**
     * 删除上课预约
     */
    @PreAuthorize("@ss.hasPermi('debao:appoint:remove')")
    @Log(title = "上课预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appointService.deleteAppointByIds(ids));
    }

    /**
     * 获取课程学员
     */
    @GetMapping("/courseUserList/{courseId}")
    public AjaxResult courseUserList(@PathVariable Long courseId) {
        return AjaxResult.success(courseCardService.courseUserList(courseId));
    }

    /**
     * 获取教练发布的课程卡列表
     */
    @GetMapping("/list/{coachId}")
    public AjaxResult list(@PathVariable("coachId") Long coachId) {
        List<CourseCard> courseCards = courseCardService.selectCourseCardList(new CourseCard().setCoachId(coachId).setOnline(1L));
        return AjaxResult.success(courseCards);
    }

}
